function Page(settings) {
    this.settings = settings;
    this.init();
 }
 //默认配置
 Page.prototype = {
     init: function() {
     this.create();
 },
 create: function() {
    var _template = `
    <div class="label pre page_home">首页</div>
    <div class="label pre page_up">上一页</div>
    <div class="page_view">
        <ul class="page_view_ul justify-center align-center">
        </ul>
    </div>
    <div class="label next page_down">下一页</div>
    <div class="label next page_trailer">尾页</div>
    <div class="tips">第${this.settings.nowPage}/${this.settings.countPage}页，共${this.settings.count}条数据</div>
     `;
     $(this.settings.container).html(_template);
     this.refreshDom(this.settings);
     this.bindEvent();
     },
 bindEvent: function() {
     var _this = this;
         //跳转首页
     $(this.settings.container).on("click", ".page_home", function() {
         var newpages = 1;
         _this.settings.nowPage = newpages;
         _this.settings.callBack(_this.settings.nowPage)
         _this.refreshDom(this.settings);
     });
     //跳转上一页
     $(this.settings.container).on("click", ".page_up", function() {
         var newpages = _this.settings.nowPage;
         newpages--;
         if(newpages < 1) {
             newpages = 1
             _this.settings.nowPage = newpages
         } else {
             _this.settings.nowPage = newpages
         }
     _this.settings.callBack(_this.settings.nowPage)
         _this.refreshDom(this.settings);
     });
     //跳转下一页
     $(this.settings.container).on("click", ".page_down", function() {
         var newpages = _this.settings.nowPage;
         newpages++;
         if(newpages > _this.settings.countPage) {
             newpages = _this.settings.countPage
             _this.settings.nowPage = newpages
         } else {
             _this.settings.nowPage = newpages
         }
         _this.settings.callBack(_this.settings.nowPage)
         _this.refreshDom(this.settings);
     });
     //跳转末页
     $(this.settings.container).on("click", ".page_trailer", function() {
         var newpages = _this.settings.countPage;
         _this.settings.nowPage = newpages;
         _this.settings.callBack(_this.settings.nowPage)
         _this.refreshDom(this.settings);
     });
     //Go跳转
     $(this.settings.container).on("click", ".page_btn", function() {
         var inputText = $(".page_input").val() - 0;
         if(inputText < 1 || inputText > _this.settings.countPage) {
             alert("输入的页面不正确，请重新输入")
         } else {
             _this.settings.nowPage = inputText;
             _this.settings.callBack(_this.settings.nowPage)
             _this.refreshDom(this.settings);
             //                establish(objpage);
             //外部的ajax
         }
         });
     },
     refreshDom: function() {
         var _this = this;
         $(".paging .dot").remove();
         var countPage = this.settings.countPage;
         var showPageCount = this.settings.showPageCount;
         var nowPage = this.settings.nowPage - 0;
         var count = this.settings.count;
         var bian = Math.floor((showPageCount - 1) / 2);
         $(".paging .tips").html(`第${nowPage}/${countPage}页，共${count}条数据`);
         var html = "";
         if(nowPage - bian <= 0) {
             for(var i = 1; i < showPageCount + 1; i++) {
                 var index = i;
                 if(nowPage == index) {
                 pageHtml = `    <li index="${i}" class="dot dot-active">${i}</li>`;
                 } else {
                 pageHtml = `    <li  index="${i}" class="dot">${i}</li>`;
                 }
             html += pageHtml;
             }
         } else if(nowPage - bian > 0 && nowPage + bian < countPage) {
             var num = nowPage - bian;
             for(var i = num; i < (num + showPageCount); i++) {
                 var index = i;
                 if(nowPage == index) {
                     pageHtml = `    <li index="${i}" class="dot dot-active">${i}</li>`;
                 } else {
                     pageHtml = `    <li  index="${i}" class="dot">${i}</li>`;
                 }
             html += pageHtml;
             }
 
         } else if(nowPage + bian >= countPage) {
             var numAll = countPage - showPageCount + 1;
             for(var i = numAll; i < (numAll + showPageCount); i++) {
                 var index = i;
                 if(nowPage == index) {
                     pageHtml = `    <li index="${i}" class="dot dot-active">${i}</li>`;
                 } else {
                     pageHtml = `    <li  index="${i}" class="dot">${i}</li>`;
                 }
             html += pageHtml;
         }
     }
 
     $(".paging .page_view_ul").append(html)
 
     $(".paging .dot").click(function() {
        _this.settings.nowPage = $(this).attr("index")-0;
        _this.settings.callBack($(this).attr("index")-0)
        _this.refreshDom(this.settings);
     })
     }
 };
     var pageInit = function(opts) {
         return new Page(opts);
     };
 
     window.pageInit = $.pageInit = pageInit;
     
     